#ifndef UTI_DB_H_
#define UTI_DB_H_
#pragma once
#include "uti_barseries.h"

#include "KompexSQLitePrerequisites.h"
#include "KompexSQLiteDatabase.h"
#include "KompexSQLiteStatement.h"
#include "KompexSQLiteException.h"
#include "KompexSQLiteStreamRedirection.h"
#include "KompexSQLiteBlob.h"

#include <iostream>
#include <exception>
using namespace Kompex;


class DB
{
public:

	//DB(BarInfo* pbar, BarSeries_broad** ppbarserbroad, unsigned int cnt);

	DB(BarInfo* pbar, unsigned int agoday, BarSeries** ppbarser);

	~DB();

	bool ReadData();

private:

	bool Initvariables(BarInfo* pbar, unsigned int rdnum);

	bool InitDBInfo(BarSeries** ppbarser);

	void DestroyDBInfo();

	bool InitBuffer();

	void DestroyBuffer();

	bool CheckDBFile();




	bool OpenDB(unsigned int index);

	bool ReadDB(unsigned int index);

	bool CloseDB(unsigned int index);



	void SetSystime(SYSTEMTIME& systm, const char* ptime);


private:

	typedef struct DBINFO
	{
		DBINFO(string& _dbname, string& _tbname, string& _csvname, BarSeries** _ppbarser)
		{
			pdb = NULL;
			pst = NULL;

			dbname = _dbname;
			tbname = _tbname;
			csvname = _csvname;
			ppbarser = _ppbarser;
		};

		string dbname;
		string tbname;
		BarSeries** ppbarser;

		SQLiteDatabase* pdb;
		SQLiteStatement* pst;

		string csvname;

	}DBINFO;


	vector<DBINFO*> m_vpdbinfo;

	char* m_buffer;

	unsigned int m_agoday;

	string m_dbf;

	string m_tbname;

	unsigned int m_readcnt;
};





#endif